import java.util.Stack;

class MinStack {
    Stack<Integer> stack = new Stack<>() ;
    Stack<Integer> minStack = new Stack<>() ;

    public MinStack() {
        this.stack = new Stack<>() ;
        this.minStack = new Stack<>() ;

    }

    public void push(int val) {
        stack.push(val) ;
        if(minStack.empty()){
            minStack.push(val) ;
        }else{
            if(val <= minStack.peek()){
                minStack.push(val) ;
            }
        }
    }

    public void pop() {
        int ret = stack.pop() ;
        if(ret == minStack.peek()){
            minStack.pop() ;
        }

    }

    public int top() {
        return this.stack.peek() ;
    }

    public int getMin() {
        return   this.minStack.peek() ;
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */